package com.key.w8.http1.entity;

import io.netty.handler.codec.http.DefaultHttpHeaders;
import io.netty.handler.codec.http.HttpHeaders;
import io.netty.handler.codec.http.HttpMethod;
import io.netty.handler.codec.http.HttpVersion;

import java.util.HashMap;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;

/**
 * @Author: k8
 * @CreateTime: 2025-03-10
 * @Version: 1.0
 */
public class HttpRequest extends HttpObject{


    private HttpMethod method;
    private String uri;

    private Map<String, List<String>> parameters;

    public void setParameters(Map<String, List<String>> parameters) {
        this.parameters = parameters;
    }
    public Map<String, List<String>> getUrlParameters(){
        return this.parameters;
    }
    public void addUrlParameter(String key , String value){
        if (this.parameters == null){
            this.parameters = new HashMap<>();
        }
        List<String> values = this.parameters.get(key);
        if (values == null){
            values = new LinkedList<>();
            this.parameters.put(key,values);
        }
        values.add(value);
    }
    public Map<String, List<String>> parameters(){
        return this.parameters;
    }


    public HttpRequest(HttpHeaders headers, HttpVersion version, HttpMethod method,String uri) {
        super(headers,version);
        assert method != null;
        assert uri != null;
        this.method = method;
        this.uri = uri;
    }
    public HttpRequest(HttpVersion version, HttpMethod method,String uri) {
        super(new DefaultHttpHeaders(true),version);
        assert method != null;
        assert uri != null;
        this.method = method;
        this.uri = uri;
    }
    public String uri(){
        return this.uri;
    }


    public HttpMethod method() {
        return method;
    }

    public void setMethod(HttpMethod method) {
        this.method = method;
    }


}
